Home > Java Programming > Declarations and Access Control > Questions and Answers
Exercise:
01. |
What will be the output of the program? class Super{ public Integer getLength(){ return new Integer(4); } } public class Sub extends Super{ public Long getLength(){ return new Long(5); } public static void main(String[] args){ Super sooper = new Super(); Sub sub = new Sub(); System.out.println( sooper.getLength().toString() + "," + sub.getLength().toString() ); } } | |||||||||||
|
02. |
What will be the output of the program? import java.util.*; public class NewTreeSet2 extends NewTreeSet{ public static void main(String [] args){ NewTreeSet2 t = new NewTreeSet2(); t.count(); } } protected class NewTreeSet{ void count(){ for (int x = 0; x < 7; x++,x++ ){ System.out.print(" " + x); } } } | |||||||||||
|
03. |
interface Base{ boolean m1 ( ); byte m2(short s); } Which of the two code fragments will compile? 1. interface Base2 implements Base {} 2. abstract class Class2 extends Base { public boolean m1(){ return true; }} 3. abstract class Class2 implements Base {} 4. abstract class Class2 implements Base { public boolean m1(){ return (7 > 4); }} 5. abstract class Class2 implements Base { protected boolean m1(){ return (5 > 7) }} | |||||||||||
|
04. |
Which three form part of correct array declarations? 1. public int a [ ] 2. static int [ ] a 3. public [ ] int a 4. private int a [3] 5. private int [3] a [ ] 6. public final int [ ] a | |||||||||||
|
05. |
Which two statements are true for any concrete class implementing the java.lang.Runnable interface? 1. You can extend the Runnable interface as long as you override the public run ( ) method. 2. The class must contain a method called run ( ) from which all code for that thread will be initiated. 3. The class must contain an empty public void method named run ( ). 4. The class must contain a public void method named runnable ( ). 5. The class definition must include the words implements Threads and contain a method called run ( ). 6. The mandatory method must be public, with a return type of void, must be called run ( ), and cannot take any arguments. | |||||||||||
|